import { Buffer, utf8Slice } from "./buffer";
import { BROWSIX_SHM_OFF, BROWSIX_SHM_SIZE, PER_BLOCKING } from "./constants";

interface UOutstandingMap {
	[i: number]: SyscallCallback;
}

export interface SyscallCallback {
	(...args: any[]): void;
}

export interface SignalHandler {
	(data: SyscallResponse): void;
}

// from BrowserFS.  Copied to avoid this module pulling in any dependencies
export enum ErrorCode {
	EPERM, ENOENT, EIO, EBADF, EACCES, EBUSY, EEXIST, ENOTDIR, EISDIR, EINVAL,
	EFBIG, ENOSPC, EROFS, ENOTEMPTY, ENOTSUP
}

// from BrowserFS.  Copied to avoid this module pulling in any dependencies
let fsErrors: { [n: string]: string } = {
	EPERM: 'Operation not permitted.',
	ENOENT: 'No such file or directory.',
	EIO: 'Input/output error.',
	EBADF: 'Bad file descriptor.',
	EACCES: 'Permission denied.',
	EBUSY: 'Resource busy or locked.',
	EEXIST: 'File exists.',
	ENOTDIR: 'File is not a directory.',
	EISDIR: 'File is a directory.',
	EINVAL: 'Invalid argument.',
	EFBIG: 'File is too big.',
	ENOSPC: 'No space left on disk.',
	EROFS: 'Cannot modify a read-only file system.',
	ENOTEMPTY: 'Directory is not empty.',
	ENOTSUP: 'Operation is not supported.',
};

// from BrowserFS.  Copied to avoid this module pulling in any dependencies
export class ApiError {
	type: ErrorCode;
	message: string;
	code: string;

	/**
	 * Represents a BrowserFS error. Passed back to applications after a failed
	 * call to the BrowserFS API.
	 *
	 * Error codes mirror those returned by regular Unix file operations, which is
	 * what Node returns.
	 * @constructor ApiError
	 * @param type The type of the error.
	 * @param [message] A descriptive error message.
	 */
	constructor(type: ErrorCode, message?: string) {
		this.type = type;
		this.code = ErrorCode[type];
		if (message != null) {
			this.message = message;
		} else {
			this.message = fsErrors[type];
		}
	}

	public toString(): string {
		return this.code + ": " + fsErrors[this.code] + " " + this.message;
	}
}

function convertApiErrors(e: any): any {
	if (!e)
		return e;

	// if it looks like an ApiError, and smells like an ApiError...
	if (!e.hasOwnProperty('type') || !e.hasOwnProperty('message') || !e.hasOwnProperty('code'))
		return e;

	return new ApiError(e.type, e.message);
}

export class SyscallResponse {
	constructor(
		public id: number,
		public name: string,
		public args: any[]) { }

	private static requiredOnData: string[] = ['id', 'name', 'args'];

	static From(ev: MessageEvent): SyscallResponse {
		if (!ev.data)
			return;
		for (let i = 0; i < SyscallResponse.requiredOnData.length; i++) {
			if (!ev.data.hasOwnProperty(SyscallResponse.requiredOnData[i]))
				return;
		}
		let args: any[] = ev.data.args.map(convertApiErrors);
		return new SyscallResponse(ev.data.id, ev.data.name, args);
	}
}

let syncMsg: any = {
	trap: 0 | 0,
	args: [0 | 0, 0 | 0, 0 | 0, 0 | 0, 0 | 0, 0 | 0],
};

export class USyscalls {
	SHM_SIZE = BROWSIX_SHM_SIZE;
	SHM_BUF_SIZE = BROWSIX_SHM_SIZE - BROWSIX_SHM_OFF
	SHM_OFF = BROWSIX_SHM_OFF;
	private PER_BLOCKING = PER_BLOCKING;
	private shm: SharedArrayBuffer | ArrayBuffer = null;
	private shmU8: Uint8Array = null;
	private shm32: Int32Array = null;
	private waitOff = 0; // avoid using first 4096 bytes.
	private msgIdSeq: number = 1;
	private port: MessagePort;
	private outstanding: UOutstandingMap = {};
	private signalHandlers: { [name: string]: SignalHandler[] } = {};

	constructor(port: MessagePort) {
		this.shm = null;
		this.shmU8 = null;
		this.shm32 = null;
		this.waitOff = 0;

		this.port = port;
		this.port.onmessage = this.resultHandler.bind(this);
	}

	putShmString(str, off = this.SHM_OFF) {
		const buffer = Buffer.from(str, 'utf-8');
		const uint8Array = new Uint8Array(buffer);

		let ptr = 0
		let shmU8 = this.shmU8;
		let i = 0;
		for (i = 0; i < this.SHM_BUF_SIZE; i++) {
			shmU8[off + i] = uint8Array[ptr + i];
			if (!uint8Array[ptr + i])
				break;
		}
		//return off;
		return off + i + 1;
	}

	getShm(len) {
        if (len > this.SHM_BUF_SIZE)
          len = this.SHM_BUF_SIZE;

        let off = this.SHM_OFF;
        return new Uint8Array(this.shm, off, len);
      }

	getShmAt(off, len) {
		if (off + len > this.SHM_BUF_SIZE)
			len = this.SHM_BUF_SIZE - off;

		return new Uint8Array(this.shm, off, len);
	}

  getStringAt(ptr: number): string {
		let s = new Uint8Array(this.shm, ptr);

		let len = 0;
		while (s[len] !== 0)
			len++;

		return utf8Slice(s, 0, len);
	}

  getStringArrayAt(ptr: number): string[] {

		let arr: string[] = [];
		let i = 0;
		for (let i = 0; this.shm32[(ptr + i) >> 2] !== 0; i += 4) {
			let s = this.getStringAt(this.shm32[(ptr + i) >> 2]);
			arr.push(s);
		}
		return arr;
	}

	copyFromUser(shmBuf, ptr, buffer) {
        // shmBuf.set(HEAPU8.subarray(ptr, ptr+shmBuf.length));
        for (let i = 0; i < shmBuf.length; i++)
          shmBuf[i] = buffer[ptr + i];
    }
	copyToUser(ptr, len, buffer?) {
		let buf = buffer

		if (!buf) {
			buf = Buffer.alloc(len)
		}
		buffer.set(this.getShmAt(ptr, len));
		return buffer
	}

	public addEventListener(type: string, handler: SignalHandler): void {
		if (!handler)
			return;
		if (this.signalHandlers[type])
			this.signalHandlers[type].push(handler);
		else
			this.signalHandlers[type] = [handler];
	}
	private resultHandler(ev: MessageEvent): void {
		let response = SyscallResponse.From(ev);
		if (!response) {
			console.log('bad usyscall message, dropping');
			console.log(ev);
			return;
		}

		// signals are named, everything else is a response
		// to a message _we_ sent.  Signals include the
		// 'init' message with our args + environment.
		if (response.name) {
			let handlers = this.signalHandlers[response.name];
			if (handlers) {
				for (let i = 0; i < handlers.length; i++)
					handlers[i](response);
			} else {
				console.log('unhandled signal ' + response.name);
			}
			return;
		}

		// TODO: handle reject
		this.complete(response.id, response.args);
	}

	private complete(id: number, args: any[]): void {
		let cb = this.outstanding[id];
		delete this.outstanding[id];
		if (cb) {
			cb.apply(undefined, args);
		} else {
			console.log('unknown callback for msg ' + id + ' - ' + args);
		}
	}

	private nextMsgId(): number {
		return ++this.msgIdSeq;
	}

	public personality(cb, sab?: SharedArrayBuffer, waitOff?: number) {

		this.shm = new SharedArrayBuffer(this.SHM_SIZE)
		this.shm32 = new Int32Array(this.shm);
		this.shmU8 = new Uint8Array(this.shm);
		this.waitOff = this.waitOff;

		this.async(
			cb, 'personality',
			[this.PER_BLOCKING, this.shm, this.waitOff], []);
	}

	public async(cb: SyscallCallback, name: string, args: any[], transferrables?: any[]): void {
		if (!transferrables)
			transferrables = undefined;

		const msgId = this.nextMsgId();
		this.outstanding[msgId] = cb;
		this.port.postMessage(
			{
				id: msgId,
				name: name,
				args: args,
			},
			transferrables);
	}

	public sync(trap: number, a1?: number, a2?: number, a3?: number, a4?: number, a5?: number, a6?: number): any {
		syncMsg.trap = trap | 0;
		syncMsg.args[0] = a1 | 0;
		syncMsg.args[1] = a2 | 0;
		syncMsg.args[2] = a3 | 0;
		syncMsg.args[3] = a4 | 0;
		syncMsg.args[4] = a5 | 0;
		syncMsg.args[5] = a6 | 0;
		this.port.postMessage(syncMsg);
		console.log('waiting (' + (this.waitOff >> 2) + ')');
		let r = Atomics.wait(this.shm32, this.waitOff >> 2, 0);
		Atomics.store(this.shm32, this.waitOff >> 2, 0);
		console.log('returned from wait: ' + r);
		return Atomics.load(this.shm32, (this.waitOff >> 2) + 1);
	}

	public syscallAsync(name: string, args: any[], transferrables: any[]): Promise<any[]> {
		return new Promise((resolve) => {
			const msgId = ++this.msgIdSeq;
			this.outstanding[msgId] = (...args: any[]) => resolve(args);
			this.port.postMessage({
				args,
				id: msgId,
				name,
			}, transferrables);
		});
	}
}

declare var global: any;
export function getGlobal(): any {
	// logic from gopherjs
	if (typeof window !== "undefined") { /* web page */
		return <any>window;
	} else if (typeof self !== "undefined") { /* web worker */
		return <any>self;
	} else if (typeof global !== "undefined") { /* Node.js */
		return <any>global;
	} else { /* others (e.g. Nashorn) */
		return <any>this;
	}
}

export const syscall = new USyscalls(getGlobal());

// https://github.com/torvalds/linux/blob/master/arch/x86/entry/syscalls/syscall_32.tbl
export enum SYS {
    RESTART_SYSCALL = 0,    // sys_restart_syscall
    EXIT = 1,               // sys_exit
    FORK = 2,               // sys_fork
    READ = 3,               // sys_read
    WRITE = 4,              // sys_write
    OPEN = 5,               // sys_open
    CLOSE = 6,              // sys_close
    WAITPID = 7,            // sys_waitpid
    CREAT = 8,              // sys_creat
    LINK = 9,               // sys_link
    UNLINK = 10,            // sys_unlink
    EXECVE = 11,            // sys_execve
    CHDIR = 12,             // sys_chdir
    TIME = 13,              // sys_time32
    MKNOD = 14,             // sys_mknod
    CHMOD = 15,             // sys_chmod
    LCHOWN = 16,            // sys_lchown16
    BREAK = 17,             // sys_break
    OLDSTAT = 18,          // sys_stat
    LSEEK = 19,            // sys_lseek            compat_sys_lseek
    getpid = 20,           // sys_getpid
    MOUNT = 21,            // sys_mount
    UMOUNT = 22,           // sys_oldumount
    SETUID = 23,           // sys_setuid16
    GETUID = 24,           // sys_getuid16
    STIME = 25,            // sys_stime32
    PTRACE = 26,           // sys_ptrace           compat_sys_ptrace
    ALARM = 27,            // sys_alarm
    OLDFSTAT = 28,         // sys_fstat
    PAUSE = 29,            // sys_pause
    UTIME = 30,            // sys_utime32
    STTY = 31,
    GTTY = 32,
    ACCESS = 33,           // sys_access
    NICE = 34,             // sys_nice
    FTIME = 35,
    SYNC = 36,             // sys_sync
    KILL = 37,             // sys_kill
    RENAME = 38,           // sys_rename
    MKDIR = 39,            // sys_mkdir
    RMDIR = 40,            // sys_rmdir
    DUP = 41,              // sys_dup
    PIPE = 42,             // sys_pipe
    TIMES = 43,            // sys_times            compat_sys_times
    PROF = 44,
    BRK = 45,               // sys_brk
    SETGID = 46,           // sys_setgid16
    GETGID = 47,           // sys_getgid16
    SIGNAL = 48,           // sys_signal
    GETEUID = 49,          // sys_geteuid16
    GETEGID = 50,          // sys_getegid16
    ACCT = 51,             // sys_acct
    UMOUNT2 = 52,          // sys_umount
    LOCK = 53,             // sys_lock
    IOCTL = 54,            // sys_ioctl           compat_sys_ioctl
    FCNTL = 55,            // sys_fcntl           compat_sys_fcntl64
    MXP = 56,
    SETPGID = 57,          // sys_setpgid
    ULIMIT = 58,
    OLDOLDUNAME = 59,       // sys_olduname
    UMASK = 60,            // sys_umask
    CHROOT = 61,           // sys_chroot
    USTAT = 62,            // sys_ustat           compat_sys_ustat
    DUP2 = 63,             // sys_dup2
    GETPPID = 64,          // sys_getppid
    GETPGRP = 65,          // sys_getpgrp
    SETSID = 66,           // sys_setsid
    SIGACTION = 67,        // sys_sigaction       compat_sys_sigaction
    SGETMASK = 68,        // sys_sgetmask
    SSETMASK = 69,        // sys_ssetmask
    SETREUID = 70,        // sys_setreuid16
    SETREGID = 71,        // sys_setregid16
    SIGSUSPEND = 72,       // sys_sigsuspend
    SIGPENDING = 73,      // sys_sigpending       compat_sys_sigpending
    SETHOSTNAME = 74,     // sys_sethostname
    SETRLIMIT = 75,       // sys_setrlimit       compat_sys_setrlimit
    GETRLIMIT = 76,        // sys_old_getrlimit    compat_sys_old_getrlimit
    GETRUSAGE = 77,        // sys_getrusage       compat_sys_getrusage
    GETTIMEOFDAY = 78,     // sys_gettimeofday    compat_sys_gettimeofday
    SETTIMEOFDAY = 79,     // sys_settimeofday    compat_sys_settimeofday
    GETGROUPS = 80,        // sys_getgroups16
    SETGROUPS = 81,        // sys_setgroups16
    SELECT = 82,           // sys_old_select      compat_sys_old_select
    SYMLINK = 83,          // sys_symlink
    OLDLSTAT = 84,         // sys_lstat
    READLINK = 85,         // sys_readlink
    USELIB = 86,           // sys_uselib
    SWAPON = 87,           // sys_swapon
    REBOOT = 88,           // sys_reboot
    READDIR = 89,          // sys_old_readdir     compat_sys_old_readdir
    MMAP = 90,             // sys_old_mmap        compat_sys_ia32_mmap
    MUNMAP = 91,           // sys_munmap
    TRUNCATE = 92,         // sys_truncate       compat_sys_truncate
    FTRUNCATE = 93,        // sys_ftruncate      compat_sys_ftruncate
    FCHMOD = 94,           // sys_fchmod
    FCHOWN = 95,           // sys_fchown16
    GETPRIORITY = 96,      // sys_getpriority
    SETPRIORITY = 97,      // sys_setpriority
    PROFIL = 98,
    STATFS = 99,           // sys_statfs         compat_sys_statfs
    FSTATFS = 100,         // sys_fstatfs        compat_sys_fstatfs
    IOPERM = 101,          // sys_ioperm
    SOCKETCALL = 102,      // sys_socketcall     compat_sys_socketcall
    SYSLOG = 103,          // sys_syslog
    SETITIMER = 104,       // sys_setitimer      compat_sys_setitimer
    GETITIMER = 105,       // sys_getitimer      compat_sys_getitimer
    STAT = 106,            // sys_newstat        compat_sys_newstat
    LSTAT = 107,           // sys_newlstat       compat_sys_newlstat
    FSTAT = 108,           // sys_newfstat       compat_sys_newfstat
    OLDUNAME = 109,        // sys_uname
    IOPL = 110,            // sys_iopl
    VHANGUP = 111,         // sys_vhangup
    IDLE = 112,
    VM86OLD = 113,         // sys_vm86old       sys_ni_syscall
    WAIT4 = 114,           // sys_wait4         compat_sys_wait4
    SWAPOFF = 115,         // sys_swapoff
    SYSINFO = 116,         // sys_sysinfo       compat_sys_sysinfo
    IPC = 117,             // sys_ipc          compat_sys_ipc
    FSYNC = 118,           // sys_fsync
    SIGRETURN = 119,       // sys_sigreturn     compat_sys_sigreturn
    CLONE = 120,           // sys_clone        compat_sys_ia32_clone
    SETDOMAINNAME = 121,   // sys_setdomainname
    UNAME = 122,           // sys_newuname
    MODIFY_LDT = 123,      // sys_modify_ldt
    ADJTIMEX = 124,        // sys_adjtimex_time32
    MPROTECT = 125,        // sys_mprotect
    SIGPROCMASK = 126,     // sys_sigprocmask   compat_sys_sigprocmask
    CREATE_MODULE = 127,
    INIT_MODULE = 128,     // sys_init_module
    DELETE_MODULE = 129,   // sys_delete_module
    GET_KERNEL_SYMS = 130,
    QUOTACTL = 131,        // sys_quotactl
    GETPGID = 132,
	// sys_getpgid
    FCHDIR = 133,          // sys_fchdir
    BDFLUSH = 134,         // sys_ni_syscall
    SYSFS = 135,           // sys_sysfs
    PERSONALITY = 136,     // sys_personality
    AFS_SYSCALL = 137,
    SETFSUID = 138,       // sys_setfsuid16
    SETFSGID = 139,       // sys_setfsgid16
    _LLSEEK = 140,         // sys_llseek
    GETDENTS = 141,        // sys_getdents      compat_sys_getdents
    _NEWSELECT = 142,      // sys_select        compat_sys_select
    FLOCK = 143,           // sys_flock
    MSYNC = 144,           // sys_msync
    READV = 145,           // sys_readv
    WRITEV = 146,          // sys_writev
    GETSID = 147,          // sys_getsid
    FDATASYNC = 148,       // sys_fdatasync
    _SYSCTL = 149,         // sys_ni_syscall
    MLOCK = 150,           // sys_mlock
    MUNLOCK = 151,         // sys_munlock
    MLOCKALL = 152,        // sys_mlockall
    MUNLOCKALL = 153,      // sys_munlockall
    SCHED_SETPARAM = 154,  // sys_sched_setparam
    SCHED_GETPARAM = 155,  // sys_sched_getparam
    SCHED_SETSCHEDULER = 156,  // sys_sched_setscheduler
    SCHED_GETSCHEDULER = 157,  // sys_sched_getscheduler
    SCHED_YIELD = 158,     // sys_sched_yield
    SCHED_GET_PRIORITY_MAX = 159,  // sys_sched_get_priority_max
    SCHED_GET_PRIORITY_MIN = 160,  // sys_sched_get_priority_min
    SCHED_RR_GET_INTERVAL = 161,  // sys_sched_rr_get_interval_time32
    NANOSLEEP = 162,       // sys_nanosleep_time32
    MREMAP = 163,          // sys_mremap
    SETRESUID = 164,       // sys_setresuid16
    GETRESUID = 165,       // sys_getresuid16
    VM86 = 166,            // sys_vm86          sys_ni_syscall
    QUERY_MODULE = 167,
    SYS_SWAPOFF = 168,            // sys_poll
    NFSSERVCTL = 169,
    SETRESGID = 170,       // sys_setresgid16
    GETRESGID = 171,       // sys_getresgid16
    PRCTL = 172,           // sys_prctl
    RT_SIGRETURN = 173,    // sys_rt_sigreturn  compat_sys_rt_sigreturn
    RT_SIGACTION = 174,     // sys_rt_sigaction  compat_sys_rt_sigaction
    RT_SIGPROCMASK = 175,   // sys_rt_sigprocmask compat_sys_rt_sigprocmask
    RT_SIGPENDING = 176,    // sys_rt_sigpending  compat_sys_rt_sigpending
    RT_SIGTIMEDWAIT = 177,  // sys_rt_sigtimedwait_time32 compat_sys_rt_sigtimedwait_time32
    RT_SIGQUEUEINFO = 178,  // sys_rt_sigqueueinfo  compat_sys_rt_sigqueueinfo
    RT_SIGSUSPEND = 179,    // sys_rt_sigsuspend  compat_sys_rt_sigsuspend
    PREAD64 = 180,         // sys_ia32_pread64
    PWRITE64 = 181,        // sys_ia32_pwrite64
    CHOWN = 182,           // sys_chown16
    GETCWD = 183,          // sys_getcwd
    CAPGET = 184,          // sys_capget
    CAPSET = 185,          // sys_capset
    SIGALTSTACK = 186,     // sys_sigaltstack    compat_sys_sigaltstack
    SENDFILE = 187,        // sys_sendfile      compat_sys_sendfile
    GETPMSG = 188,
    PUTPMSG = 189,
    VFORK = 190,           // sys_vfork
    UGETRLIMIT = 191,      // sys_getrlimit     compat_sys_getrlimit
    MMAP2 = 192,           // sys_mmap_pgoff
    TRUNCATE64 = 193,      // sys_ia32_truncate64
    FTRUNCATE64 = 194,     // sys_ia32_ftruncate64
    STAT64 = 195,          // sys_stat64        compat_sys_ia32_stat64
    LSTAT64 = 196,         // sys_lstat64       compat_sys_ia32_lstat64
    FSTAT64 = 197,         // sys_fstat64       compat_sys_ia32_fstat64
    LCHOWN32 = 198,        // sys_lchown
    GETUID32 = 199,        // sys_getuid
    GETGID32 = 200,        // sys_getgid
    GETEUID32 = 201,       // sys_geteuid
    GETEGID32 = 202,       // sys_getegid
    SETREUID32 = 203,      // sys_setreuid
    SETREGID32 = 204,      // sys_setregid
    GETGROUPS32 = 205,     // sys_getgroups
    SETGROUPS32 = 206,     // sys_setgroups
    FCHOWN32 = 207,        // sys_fchown
    SETRESUID32 = 208,     // sys_setresuid
    GETRESUID32 = 209,     // sys_getresuid
    SETRESGID32 = 210,     // sys_setresgid
    GETRESGID32 = 211,     // sys_getresgid
    CHOWN32 = 212,         // sys_chown
    SETUID32 = 213,        // sys_setuid
    SETGID32 = 214,        // sys_setgid
    SETFSUID32 = 215,      // sys_setfsuid
    SETFSGID32 = 216,      // sys_setfsgid
    PIVOT_ROOT = 217,      // sys_pivot_root
    MINCORE = 218,        // sys_mincore
    MADVISE = 219,         // sys_madvise
    GETDENTS64 = 220,      // sys_getdents64
    FCNTL64 = 221,         // sys_fcntl64       compat_sys_fcntl64
    GETTID = 224,          // sys_gettid
    READAHEAD = 225,       // sys_ia32_readahead
    SETXATTR = 226,        // sys_setxattr
    LSETXATTR = 227,       // sys_lsetxattr
    FSETXATTR = 228,       // sys_fsetxattr
    GETXATTR = 229,        // sys_getxattr
    LGETXATTR = 230,       // sys_lgetxattr
    FGETXATTR = 231,       // sys_fgetxattr
    LISTXATTR = 232,       // sys_listxattr
    LLISTXATTR = 233,      // sys_llistxattr
    FLISTXATTR = 234,      // sys_flistxattr
    REMOVEXATTR = 235,     // sys_removexattr
    LREMOVEXATTR = 236,    // sys_lremovexattr
    FREMOVEXATTR = 237,    // sys_fremovexattr
    TKILL = 238,           // sys_tkill
    SENDFILE64 = 239,      // sys_sendfile64
    FUTEX = 240,           // sys_futex_time32
    SCHED_SETAFFINITY = 241,  // sys_sched_setaffinity     compat_sys_sched_setaffinity
    SCHED_GETAFFINITY = 242,  // sys_sched_getaffinity     compat_sys_sched_getaffinity
    SET_THREAD_AREA = 243,  // sys_set_thread_area
    GET_THREAD_AREA = 244,  // sys_get_thread_area
    IO_SETUP = 245,       // sys_io_setup          compat_sys_io_setup
    IO_DESTROY = 246,     // sys_io_destroy
    IO_GETEVENTS = 247,    // sys_io_getevents_time32
    IO_SUBMIT = 248,      // sys_io_submit        compat_sys_io_submit
    IO_CANCEL = 249,      // sys_io_cancel
    FADVISE64 = 250,      // sys_ia32_fadvise64
    // 251 is available for reuse (was briefly sys_set_zone_reclaim)
    EXIT_GROUP = 252,     // sys_exit_group     -
    LOOKUP_DCOOKIE = 253, // sys_lookup_dcookie
    EPOL_CREATE = 254,    // sys_epoll_create
    EPOL_CTL = 255,       // sys_epoll_ctl
    EPOL_WAIT = 256,      // sys_epoll_wait
    REMAP_FILE_PAGES = 257,  // sys_remap_file_pages
    SET_TID_ADDRESS = 258,  // sys_set_tid_address
    TIMER_CREATE = 259,    // sys_timer_create    compat_sys_timer_create
    TIMER_SETTIME = 260,   // sys_timer_settime32
    TIMER_GETTIME = 261,   // sys_timer_gettime32
    TIMER_GETOVERRUN = 262, // sys_timer_getoverrun
    TIMER_DELETE = 263,    // sys_timer_delete
    CLOCK_SETTIME = 264,   // sys_clock_settime32
    CLOCK_GETTIME = 265,   // sys_clock_gettime32
    CLOCK_GETRES = 266,    // sys_clock_getres_time32
    CLOCK_NANOSLEEP = 267, // sys_clock_nanosleep_time32
    STATFS64 = 268,        // sys_statfs64        compat_sys_statfs64
    FSTATFS64 = 269,       // sys_fstatfs64       compat_sys_fstatfs64
    TGKILL = 270,          // sys_tgkill
    UTIMES = 271,          // sys_utimes_time32
    FADVISE64_64 = 272,    // sys_ia32_fadvise64_64
    VSERVER = 273,
    MBIND = 274,           // sys_mbind
    GET_MEMPOLICY = 275,    // sys_get_mempolicy
    SET_MEMPOLICY = 276,    // sys_set_mempolicy
    MQ_OPEN = 277,         // sys_mq_open        compat_sys_mq_open
    MQ_UNLINK = 278,       // sys_mq_unlink
    MQ_TIMEDSND = 279,     // sys_mq_timedsend_time32
    MQ_TIMEDRECEIVE = 280, // sys_mq_timedreceive_time32
    MQ_NOTIFY = 281,       // sys_mq_notify      compat_sys_mq_notify
    MQ_GETSETATTR = 282,   // sys_mq_getsetattr  compat_sys_mq_getsetattr
    KEXEC_LOAD = 283,      // sys_kexec_load     compat_sys_kexec_load
    WAITID = 284,         // sys_waitid         compat_sys_waitid
    ADD_KEY = 286,         // sys_add_key
    REQUEST_KEY = 287,     // sys_request_key
    KEYCTL = 288,          // sys_keyctl         compat_sys_keyctl
    IOPRIO_SET = 289,     // sys_ioprio_set
    IOPRIO_GET = 290,     // sys_ioprio_get
    INOTIFY_INIT = 291,    // sys_inotify_init
    INOTIFY_ADD_WATCH = 292,  // sys_inotify_add_watch
    INOTIFY_RM_WATCH = 293,  // sys_inotify_rm_watch
    MIGRATE_PAGES = 294,   // sys_migrate_pages
    OPENAT = 295,         // sys_openat        compat_sys_openat
    MKDIRAT = 296,         // sys_mkdirat
    MKNODAT = 297,         // sys_mknodat
    FCHOWNAT = 298,        // sys_fchownat
    FUTIMESAT = 299,       // sys_futimesat_time32
    FSTATAT64 = 300,      // sys_fstatat64      compat_sys_ia32_fstatat64
    RENAMEAT = 302,        // sys_renameat
    LINKAT = 303,         // sys_linkat
    SYMLINKAT = 304,       // sys_symlinkat
    READLINKAT = 305,      // sys_readlinkat
    FCHMODAT = 306,        // sys_fchmodat
    FACCESSAT = 307,       // sys_faccessat
    PSELECT6 = 308,        // sys_pselect6_time32     compat_sys_pselect6_time32
    POLL = 309,            // sys_poll
    UNSHARE = 310,         // sys_unshare
    SET_ROBUST_LIST = 311, // sys_set_robust_list    compat_sys_set_robust_list
    GET_ROBUST_LIST = 312, // sys_get_robust_list    compat_sys_get_robust_list
    SPLICE = 313,          // sys_splice
    SYNC_FILE_RANGE = 314, // sys_ia32_sync_file_range
    TEE = 315,             // sys_tee
    VMSPlice = 316,        // sys_vmsplice
    MOVE_PAGES = 317,     // sys_move_pages
    GETCPU = 318,         // sys_getcpu
    EPOL_PWAIT = 319,      // sys_epoll_pwait
    UTIMENSAT = 320,      // sys_utimensat_time32
    SIGNALFD = 321,       // sys_signalfd        compat_sys_signalfd
    TIMERFD_CREATE = 322, // sys_timerfd_create
    EVENTFD = 323,        // sys_eventfd
    FALLOCATE = 324,      // sys_ia32_fallocate
    TIMERFD_SETTIME = 325, // sys_timerfd_settime32
    TIMERFD_GETTIME = 326, // sys_timerfd_gettime32
    SIGNALFD4 = 327,      // sys_signalfd4       compat_sys_signalfd4
    EVENTFD2 = 328,       // sys_eventfd2
    EPOL_CREATE1 = 329,    // sys_epoll_create1
    DUP3 = 330,            // sys_dup3
    PIPE2 = 331,           // sys_pipe2
    INOTIFY_INIT1 = 332,   // sys_inotify_init1
    PREADV = 333,          // sys_preadv         compat_sys_preadv
    PWRITEV = 334,         // sys_pwritev        compat_sys_pwritev
    RT_TGSIGQUEUEINFO = 335, // sys_rt_tgsigqueueinfo     compat_sys_rt_tgsigqueueinfo
    PERF_EVENT_OPEN = 336, // sys_perf_event_open
    RECVMMSG = 337,        // sys_recvmmsg_time32    compat_sys_recvmmsg_time32
    FANIFY_INIT = 338,     // sys_fanotify_init
    FANIFY_MARK = 339,     // sys_fanotify_mark    compat_sys_fanotify_mark
    PRLIMIT64 = 340,       // sys_prlimit64
    NAME_TO_HANDLE_AT = 341, // sys_name_to_handle_at
    OPEN_BY_HANDLE_AT = 342, // sys_open_by_handle_at    compat_sys_open_by_handle_at
    CLOCK_ADJTIME = 343,   // sys_clock_adjtime32
    SYNCFS = 344,          // sys_syncfs
    SENDMMSG = 345,        // sys_sendmmsg       compat_sys_sendmmsg
    SETNS = 346,           // sys_setns
    PROCESS_VM_READV = 347, // sys_process_vm_readv
    PROCESS_VM_WRITEV = 348, // sys_process_vm_writev
    KCMP = 349,            // sys_kcmp
    FINIT_MODULE = 350,    // sys_finit_module
    SCHED_SETATTR = 351,   // sys_sched_setattr
    SCHED_GETATTR = 352,   // sys_sched_getattr
    RENAMEAT2 = 353,       // sys_renameat2
    SECCOMP = 354,         // sys_seccomp
    GETRANDOM = 355,       // sys_getrandom
    MEMFD_CREATE = 356,     // sys_memfd_create
    BPF = 357,             // sys_bpf
    EXECVEAT = 358,        // sys_execveat       compat_sys_execveat
    SOCKET = 359,          // sys_socket
    SOCKETPAIR = 360,      // sys_socketpair
    BIND = 361,            // sys_bind
    CONNECT = 362,         // sys_connect
    LISTEN = 363,          // sys_listen
    ACCEPT4 = 364,        // sys_accept4
    GETSOCKOPT = 365,      // sys_getsockopt      sys_getsockopt
    SETSOCKOPT = 366,     // sys_setsockopt      sys_setsockopt
    Getsockname = 367,    // sys_getsockname
    Getpeername = 368,    // sys_getpeername
    SENDTO = 369,         // sys_sendto
    SENDMSG = 370,        // sys_sendmsg        compat_sys_sendmsg
    RECVFROM = 371,       // sys_recvfrom       compat_sys_recvfrom
    RECVMSG = 372,        // sys_recvmsg        compat_sys_recvmsg
    SHUTDOWN = 373,       // sys_shutdown
    USERFAULTFD = 374,    // sys_userfaultfd
    MEMBARRIER = 375,     // sys_membarrier
    MLOCK2 = 376,         // sys_mlock2
    COPY_FILE_RANGE = 377, // sys_copy_file_range
    PREADV2 =  378,        // sys_preadv2        compat_sys_preadv2
    PWRITEV2 = 379,       // sys_pwritev2       compat_sys_pwritev2
    PKEY_MPROTECT = 380,   // sys_pkey_mprotect
    PKEY_ALLOC = 381,     // sys_pkey_alloc
    PKEY_FREE = 382,      // sys_pkey_free
    STATX = 383,          // sys_statx
    ARCH_PRCTL = 384,     // sys_arch_prctl     compat_sys_arch_prctl
    IO_PGETEVENTS = 385,   // sys_io_pgetevents_time32  compat_sys_io_pgetevents
    RSEQ = 386,           // sys_rseq
    SEMGET = 393,         // sys_semget
    SEMCTL = 394,         // sys_semctl        compat_sys_semctl
    SHMGET = 395,         // sys_shmget
    SHMCTL = 396,         // sys_shmctl        compat_sys_shmctl
    SHMAT = 397,          // sys_shmat         compat_sys_shmat
    SHMDT = 398,          // sys_shmdt
    MSGGET = 399,         // sys_msgget
    MSGSND = 400,         // sys_msgsnd        compat_sys_msgsnd
    MSGRCV = 401,         // sys_msgrcv        compat_sys_msgrcv
    MSGCTL = 402,         // sys_msgctl        compat_sys_msgctl
    CLOCK_GETTIME64 = 403, // sys_clock_gettime
    CLOCK_SETTIME64 = 404, // sys_clock_settime
    CLOCK_ADJTIME64 = 405, // sys_clock_adjtime
    CLOCK_GETRES_TIME64 = 406, // sys_clock_getres
    CLOCK_NANOSLEEP_TIME64 = 407, // sys_clock_nanosleep
    TIMER_GETTIME64 = 408, // sys_timer_gettime
    TIMER_SETTIME64 = 409, // sys_timer_settime
    TIMERFD_GETTIME64 = 410, // sys_timerfd_gettime
    TIMERFD_SETTIME64 = 411, // sys_timerfd_settime
    UTIMENSAT_TIME64 = 412, // sys_utimensat
    PSELECT6_TIME64 = 413, // sys_pselect6      compat_sys_pselect6_time64
    PPOLL_TIME64 = 414,   // sys_ppoll         compat_sys_ppoll_time64
    IO_PGETEVENTS_TIME64 = 416, // sys_io_pgetevents    compat_sys_io_pgetevents_time64
    RECVMMSG_TIME64 = 417, // sys_recvmmsg      compat_sys_recvmmsg_time64
    MQ_TIMEDSND_TIME64 = 418, // sys_mq_timedsend
    MQ_TIMEDRECEIVE_TIME64 = 419, // sys_mq_timedreceive
    SEMTIMEDOP_TIME64 = 420, // sys_semtimedop
    RT_SIGTIMEDWAIT_TIME64 = 421, // sys_rt_sigtimedwait    compat_sys_rt_sigtimedwait_time64
    FUTEX_TIME64 = 422,   // sys_futex
    SCHED_RR_GET_INTERVAL_TIME64 = 423, // sys_sched_rr_get_interval
    PIDFD_SEND_SIGNAL = 424, // sys_pidfd_send_signal
    IO_URING_SETUP = 425,  // sys_io_uring_setup
    IO_URING_ENTER = 426,  // sys_io_uring_enter
    IO_URING_REGISTER = 427, // sys_io_uring_register
    OPEN_TREE = 428,      // sys_open_tree
    MOVE_MOUNT = 429,     // sys_move_mount
    FSOPEN = 430,         // sys_fsopen
    FSCONFIG = 431,       // sys_fsconfig
    FSMOUNT = 432,        // sys_fsmount
    FSPICK = 433,         // sys_fspick
    PIDFD_OPEN = 434,     // sys_pidfd_open
    CLONE3 = 435,         // sys_clone3
    CLOSE_RANGE = 436,    // sys_close_range
    OPENAT2 = 437,        // sys_openat2
    PIDFD_GETFD = 438,    // sys_pidfd_getfd
    FACCESSAT2 = 439,     // sys_faccessat2
    PROCESS_MADVISE = 440, // sys_process_madvise
    EPOL_PWAIT2 = 441,    // sys_epoll_pwait2    compat_sys_epoll_pwait2
    MOUNT_SETATTR = 442,  // sys_mount_setattr
    QUOTACTL_FD = 443,    // sys_quotactl_fd
    LANDLOCK_CREATE_RULESET = 444, // sys_landlock_create_ruleset
    LANDLOCK_ADD_RULE = 445, // sys_landlock_add_rule
    LANDLOCK_RESTRICT_SELF = 446, // sys_landlock_restrict_self
    MEMFD_SECRET = 447,  // sys_memfd_secret
    PROCESS_MRELEASE = 448, // sys_process_mrelease
    FUTEX_WAITV = 449,    // sys_futex_waitv
    SET_MEMPOLICY_HOME_NODE = 450, // sys_set_mempolicy_home_node
    CACHESTAT = 451,      // sys_cachestat
    FCHMODAT2 = 452,      // sys_fchmodat2
    MAP_SHADOW_STACK = 453, // sys_map_shadow_stack
    FUTEX_WAKE = 454,     // sys_futex_wake
    FUTEX_WAIT = 455,     // sys_futex_wait
    FUTEX_REQUEUE = 456,  // sys_futex_requeue
    STATMOUNT = 457,      // sys_statmount
    LISTMOUNT = 458,      // sys_listmount
    LSM_GET_SELF_ATTR = 459, // sys_lsm_get_self_attr
    LSM_SET_SELF_ATTR = 460, // sys_lsm_set_self_attr
    LSM_LIST_MODULES = 461, // sys_lsm_list_modules
    MSEAL = 462,          // sys_mseal
}



// export enum Syscall {
// 	SYS_READ,    // 0 read
// 	SYS_WRITE,   // 1 write
// 	SYS_OPEN,    // 2 open
// 	SYS_CLOSE,   // 3 close
// 	SYS_STAT,    // 4 stat
// 	SYS_FSTAT,   // 5 fstat
// 	SYS_LSTAT,   // 6 lstat
// 	SYS_POLL,    // 7 poll
// 	SYS_LSEEK,   // 8 lseek
// 	SYS_MMAP,    // 9 mmap
// 	SYS_MPROTECT, // 10 mprotect
// 	SYS_MUNMAP, // 11 munmap
// 	SYS_BRK, // 12 brk
// 	SYS_RT_SIGACTION, // 13 rt_sigaction
// 	SYS_RT_SIGPROCMASK, // 14 rt_sigprocmask
// 	SYS_RT_SIGRETURN, // 15 rt_sigreturn
// 	SYS_IOCTL, // 16 ioctl
// 	SYS_PREAD64, // 17 pread64
// 	SYS_PWRITE64, // 18 pwrite64
// 	SYS_READV, // 19 readv
// 	SYS_WRITEV, // 20 writev
// 	SYS_ACCESS, // 21 access
// 	SYS_PIPE, // 22 pipe
// 	SYS_SELECT, // 23 select
// 	SYS_SCHED_YIELD, // 24 sched_yield
// 	SYS_MREMAP, // 25 mremap
// 	SYS_MSYNC, // 26 msync
// 	SYS_MINCORE, // 27 mincore
// 	SYS_MADVISE, // 28 madvise
// 	SYS_SHMGET, // 29 shmget
// 	SYS_SHMAT, // 30 shmat
// 	SYS_SHMCTL, // 31 shmctl
// 	SYS_DUP, // 32 dup
// 	SYS_DUP2, // 33 dup2
// 	SYS_PAUSE, // 34 pause
// 	SYS_NANOSLEEP, // 35 nanosleep
// 	SYS_GETITIMER, // 36 getitimer
// 	SYS_ALARM, // 37 alarm
// 	SYS_SETITIMER, // 38 setitimer
// 	SYS_GETPID, // 39 getpid
// 	SYS_SENDFILE, // 40 sendfile
// 	SYS_SOCKET, // 41 socket
// 	SYS_CONNECT, // 42 connect
// 	SYS_ACCEPT, // 43 accept
// 	SYS_SENDTO, // 44 sendto
// 	SYS_RECVFROM, // 45 recvfrom
// 	SYS_SENDMSG, // 46 sendmsg
// 	SYS_RECVMSG, // 47 recvmsg
// 	SYS_SHUTDOWN, // 48 shutdown
// 	SYS_BIND, // 49 bind
// 	SYS_LISTEN, // 50 listen
// 	SYS_GETSOCKNAME, // 51 getsockname
// 	SYS_GETPEERNAME, // 52 getpeername
// 	SYS_SOCKETPAIR, // 53 socketpair
// 	SYS_SETSOCKOPT, // 54 setsockopt
// 	SYS_GETSOCKOPT, // 55 getsockopt
// 	SYS_CLONE, // 56 clone
// 	SYS_FORK, // 57 fork
// 	SYS_VFORK, // 58 vfork
// 	SYS_EXECVE, // 59 execve
// 	SYS_EXIT, // 60 exit
// 	SYS_WAIT4, // 61 wait4
// 	SYS_KILL, // 62 kill
// 	SYS_UNAME, // 63 uname
// 	SYS_SEMGET, // 64 semget
// 	SYS_SEMOP, // 65 semop
// 	SYS_SEMCTL, // 66 semctl
// 	SYS_SHMDT, // 67 shmdt
// 	SYS_MSGGET, // 68 msgget
// 	SYS_MSGSND, // 69 msgsnd
// 	SYS_MSGRCV, // 70 msgrcv
// 	SYS_MSGCTL, // 71 msgctl
// 	SYS_FCNTL, // 72 fcntl
// 	SYS_FLOCK, // 73 flock
// 	SYS_FSYNC, // 74 fsync
// 	SYS_FDATASYNC, // 75 fdatasync
// 	SYS_TRUNCATE, // 76 truncate
// 	SYS_FTRUNCATE, // 77 ftruncate
// 	SYS_GETDENTS, // 78 getdents
// 	SYS_GETCWD, // 79 getcwd
// 	SYS_CHDIR, // 80 chdir
// 	SYS_FCHDIR, // 81 fchdir
// 	SYS_RENAME, // 82 rename
// 	SYS_MKDIR, // 83 mkdir
// 	SYS_RMDIR, // 84 rmdir
// 	SYS_CREAT, // 85 creat
// 	SYS_LINK, // 86 link
// 	SYS_UNLINK, // 87 unlink
// 	SYS_SYMLINK, // 88 symlink
// 	SYS_READLINK, // 89 readlink
// 	SYS_CHMOD, // 90 chmod
// 	SYS_FCHMOD, // 91 fchmod
// 	SYS_CHOWN, // 92 chown
// 	SYS_FCHOWN, // 93 fchown
// 	SYS_LCHOWN, // 94 lchown
// 	SYS_UMASK, // 95 umask
// 	SYS_GETTIMEOFDAY, // 96 gettimeofday
// 	SYS_GETRLIMIT, // 97 getrlimit
// 	SYS_GETRUSAGE, // 98 getrusage
// 	SYS_SYSINFO, // 99 sysinfo
// 	SYS_TIMES, // 100 times
// 	SYS_PTRACE, // 101 ptrace
// 	SYS_GETUID, // 102 getuid
// 	SYS_SYSLOG, // 103 syslog
// 	SYS_GETGID, // 104 getgid
// 	SYS_SETUID, // 105 setuid
// 	SYS_SETGID, // 106 setgid
// 	SYS_GETEUID, // 107 geteuid
// 	SYS_GETEGID, // 108 getegid
// 	SYS_SETPGID, // 109 setpgid
// 	SYS_GETPPID, // 110 getppid
// 	SYS_GETPGRP, // 111 getpgrp
// 	SYS_SETSID, // 112 setsid
// 	SYS_SETREUID, // 113 setreuid
// 	SYS_SETREGID, // 114 setregid
// 	SYS_GETGROUPS, // 115 getgroups
// 	SYS_SETGROUPS, // 116 setgroups
// 	SYS_SETRESUID, // 117 setresuid
// 	SYS_GETRESUID, // 118 getresuid
// 	SYS_SETRESGID, // 119 setresgid
// 	SYS_GETRESGID, // 120 getresgid
// 	SYS_GETPGID, // 121 getpgid
// 	SYS_SETFSUID, // 122 setfsuid
// 	SYS_SETFSGID, // 123 setfsgid
// 	SYS_GETSID, // 124 getsid
// 	SYS_CAPGET, // 125 capget
// 	SYS_CAPSET, // 126 capset
// 	SYS_RT_SIGPENDING, // 127 rt_sigpending
// 	SYS_RT_SIGTIMEDWAIT, // 128 rt_sigtimedwait
// 	SYS_RT_SIGQUEUEINFO, // 129 rt_sigqueueinfo
// 	SYS_RT_SIGSUSPEND, // 130 rt_sigsuspend
// 	SYS_SIGALTSTACK, // 131 sigaltstack
// 	SYS_UTIME, // 132 utime
// 	SYS_MKNOD, // 133 mknod
// 	SYS_USELIB, // 134 uselib
// 	SYS_PERSONALITY, // 135 personality
// 	SYS_USTAT, // 136 ustat
// 	SYS_STATFS, // 137 statfs
// 	SYS_FSTATFS, // 138 fstatfs
// 	SYS_SYSFS, // 139 sysfs
// 	SYS_GETPRIORITY, // 140 getpriority
// 	SYS_SETPRIORITY, // 141 setpriority
// 	SYS_SCHED_SETPARAM, // 142 sched_setparam
// 	SYS_SCHED_GETPARAM, // 143 sched_getparam
// 	SYS_SCHED_SETSCHEDULER, // 144 sched_setscheduler
// 	SYS_SCHED_GETSCHEDULER, // 145 sched_getscheduler
// 	SYS_SCHED_GET_PRIORITY_MAX, // 146 sched_get_priority_max
// 	SYS_SCHED_GET_PRIORITY_MIN, // 147 sched_get_priority_min
// 	SYS_SCHED_RR_GET_INTERVAL, // 148 sched_rr_get_interval
// 	SYS_MLOCK, // 149 mlock
// 	SYS_MUNLOCK, // 150 munlock
// 	SYS_MLOCKALL, // 151 mlockall
// 	SYS_MUNLOCKALL, // 152 munlockall
// 	SYS_VHANGUP, // 153 vhangup
// 	SYS_MODIFY_LDT, // 154 modify_ldt
// 	SYS_PIVOT_ROOT, // 155 pivot_root
// 	SYS__SYSCTL, // 156 _sysctl
// 	SYS_PRCTL, // 157 prctl
// 	SYS_ARCH_PRCTL, // 158 arch_prctl
// 	SYS_ADJTIMEX, // 159 adjtimex
// 	SYS_SETRLIMIT, // 160 setrlimit
// 	SYS_CHROOT, // 161 chroot
// 	SYS_SYNC, // 162 sync
// 	SYS_ACCT, // 163 acct
// 	SYS_SETTIMEOFDAY, // 164 settimeofday
// 	SYS_MOUNT, // 165 mount
// 	SYS_UMOUNT2, // 166 umount2
// 	SYS_SWAPON, // 167 swapon
// 	SYS_SWAPOFF, // 168 swapoff
// 	SYS_REBOOT, // 169 reboot
// 	SYS_SETHOSTNAME, // 170 sethostname
// 	SYS_SETDOMAINNAME, // 171 setdomainname
// 	SYS_IOPL, // 172 iopl
// 	SYS_IOPERM, // 173 ioperm
// 	SYS_CREATE_MODULE, // 174 create_module
// 	SYS_INIT_MODULE, // 175 init_module
// 	SYS_DELETE_MODULE, // 176 delete_module
// 	SYS_GET_KERNEL_SYMS, // 177 get_kernel_syms
// 	SYS_QUERY_MODULE, // 178 query_module
// 	SYS_QUOTACTL, // 179 quotactl
// 	SYS_NFSSERVCTL, // 180 nfsservctl
// 	SYS_GETPMSG, // 181 getpmsg
// 	SYS_PUTPMSG, // 182 putpmsg
// 	SYS_AFS_SYSCALL, // 183 afs_syscall
// 	SYS_TUXCALL, // 184 tuxcall
// 	SYS_SECURITY, // 185 security
// 	SYS_GETTID, // 186 gettid
// 	SYS_READAHEAD, // 187 readahead
// 	SYS_SETXATTR, // 188 setxattr
// 	SYS_LSETXATTR, // 189 lsetxattr
// 	SYS_FSETXATTR, // 190 fsetxattr
// 	SYS_GETXATTR, // 191 getxattr
// 	SYS_LGETXATTR, // 192 lgetxattr
// 	SYS_FGETXATTR, // 193 fgetxattr
// 	SYS_LISTXATTR, // 194 listxattr
// 	SYS_LLISTXATTR, // 195 llistxattr
// 	SYS_FLISTXATTR, // 196 flistxattr
// 	SYS_REMOVEXATTR, // 197 removexattr
// 	SYS_LREMOVEXATTR, // 198 lremovexattr
// 	SYS_FREMOVEXATTR, // 199 fremovexattr
// 	SYS_TKILL, // 200 tkill
// 	SYS_TIME, // 201 time
// 	SYS_FUTEX, // 202 futex
// 	SYS_SCHED_SETAFFINITY, // 203 sched_setaffinity
// 	SYS_SCHED_GETAFFINITY, // 204 sched_getaffinity
// 	SYS_SET_THREAD_AREA, // 205 set_thread_area
// 	SYS_IO_SETUP, // 206 io_setup
// 	SYS_IO_DESTROY, // 207 io_destroy
// 	SYS_IO_GETEVENTS, // 208 io_getevents
// 	SYS_IO_SUBMIT, // 209 io_submit
// 	SYS_IO_CANCEL, // 210 io_cancel
// 	SYS_GET_THREAD_AREA, // 211 get_thread_area
// 	SYS_LOOKUP_DCOOKIE, // 212 lookup_dcookie
// 	SYS_EPOLL_CREATE, // 213 epoll_create
// 	SYS_EPOLL_CTL_OLD, // 214 epoll_ctl_old
// 	SYS_EPOLL_WAIT_OLD, // 215 epoll_wait_old
// 	SYS_REMAP_FILE_PAGES, // 216 remap_file_pages
// 	SYS_GETDENTS64, // 217 getdents64
// 	SYS_SET_TID_ADDRESS, // 218 set_tid_address
// 	SYS_RESTART_SYSCALL, // 219 restart_syscall
// 	SYS_SEMTIMEDOP, // 220 semtimedop
// 	SYS_FADVISE64, // 221 fadvise64
// 	SYS_TIMER_CREATE, // 222 timer_create
// 	SYS_TIMER_SETTIME, // 223 timer_settime
// 	SYS_TIMER_GETTIME, // 224 timer_gettime
// 	SYS_TIMER_GETOVERRUN, // 225 timer_getoverrun
// 	SYS_TIMER_DELETE, // 226 timer_delete
// 	SYS_CLOCK_SETTIME, // 227 clock_settime
// 	SYS_CLOCK_GETTIME, // 228 clock_gettime
// 	SYS_CLOCK_GETRES, // 229 clock_getres
// 	SYS_CLOCK_NANOSLEEP, // 230 clock_nanosleep
// 	SYS_EXIT_GROUP, // 231 exit_group
// 	SYS_EPOLL_WAIT, // 232 epoll_wait
// 	SYS_EPOLL_CTL, // 233 epoll_ctl
// 	SYS_TGKILL, // 234 tgkill
// 	SYS_UTIMES, // 235 utimes
// 	SYS_VSERVER, // 236 vserver
// 	SYS_MBIND, // 237 mbind
// 	SYS_SET_MEMPOLICY, // 238 set_mempolicy
// 	SYS_GET_MEMPOLICY, // 239 get_mempolicy
// 	SYS_MQ_OPEN, // 240 mq_open
// 	SYS_MQ_UNLINK, // 241 mq_unlink
// 	SYS_MQ_TIMEDSND, // 242 mq_timedsend
// 	SYS_MQ_TIMEDRECV, // 243 mq_timedreceive
// 	SYS_MQ_NOTIFY, // 244 mq_notify
// 	SYS_MQ_GETSETATTR, // 245 mq_getsetattr
// 	SYS_KEXEC_LOAD, // 246 kexec_load
// 	SYS_WAITID, // 247 waitid
// 	SYS_ADD_KEY, // 248 add_key
// 	SYS_REQUEST_KEY, // 249 request_key
// 	SYS_KEYCTL, // 250 keyctl
// 	SYS_IOPRIO_SET, // 251 ioprio_set
// 	SYS_IOPRIO_GET, // 252 ioprio_get
// 	SYS_INOTIFY_INIT, // 253 inotify_init
// 	SYS_INOTIFY_ADD_WATCH, // 254 inotify_add_watch
// 	SYS_INOTIFY_RM_WATCH, // 255 inotify_rm_watch
// 	SYS_MIGRATE_PAGES, // 256 migrate_pages
// 	SYS_OPENAT, // 257 openat
// 	SYS_MKDIRAT, // 258 mkdirat
// 	SYS_MKNODAT, // 259 mknodat
// 	SYS_FCHOWNAT, // 260 fchownat
// 	SYS_FUTIMESAT, // 261 futimesat
// 	SYS_NEWFSTATAT, // 262 newfstatat
// 	SYS_UNLINKAT, // 263 unlinkat
// 	SYS_RENAMEAT, // 264 renameat
// 	SYS_LINKAT, // 265 linkat
// 	SYS_SYMLINKAT, // 266 symlinkat
// 	SYS_READLINKAT, // 267 readlinkat
// 	SYS_FCHMODAT, // 268 fchmodat
// 	SYS_FACCESSAT, // 269 faccessat
// 	SYS_PSELECT6, // 270 pselect6
// 	SYS_PPOLL, // 271 ppoll
// 	SYS_UNSHARE, // 272 unshare
// 	SYS_SET_ROBUST_LIST, // 273 set_robust_list
// 	SYS_GET_ROBUST_LIST, // 274 get_robust_list
// 	SYS_SPLICE, // 275 splice
// 	SYS_TEE, // 276 tee
// 	SYS_SYNC_FILE_RANGE, // 277 sync_file_range
// 	SYS_VMSPLICE, // 278 vmsplice
// 	SYS_MOVE_PAGES, // 279 move_pages
// 	SYS_UTIMENSAT, // 280 utimensat
// 	SYS_EPOLL_PWAIT, // 281 epoll_pwait
// 	SYS_SIGNALFD, // 282 signalfd
// 	SYS_TIMERFD_CREATE, // 283 timerfd_create
// 	SYS_EVENTFD, // 284 eventfd
// 	SYS_FALLOCATE, // 285 fallocate
// 	SYS_TIMERFD_SETTIME, // 286 timerfd_settime
// 	SYS_TIMERFD_GETTIME, // 287 timerfd_gettime
// 	SYS_ACCEPT4, // 288 accept4
// 	SYS_SIGNALFD4, // 289 signalfd4
// 	SYS_EVENTFD2, // 290 eventfd2
// 	SYS_EPOLL_CREATE1, // 291 epoll_create1
// 	SYS_DUP3, // 292 dup3
// 	SYS_PIPE2, // 293 pipe2
// 	SYS_INOTIFY_INIT1, // 294 inotify_init1
// 	SYS_PREADV, // 295 preadv
// 	SYS_PWRITEV, // 296 pwritev
// 	SYS_RT_TGSIGQUEUEINFO, // 297 rt_tgsigqueueinfo
// 	SYS_PERF_EVENT_OPEN, // 298 perf_event_open
// 	SYS_RECVMMSG, // 299 recvmmsg
// 	SYS_FANOTIFY_INIT, // 300 fanotify_init
// 	SYS_FANOTIFY_MARK, // 301 fanotify_mark
// 	SYS_PRLIMIT64, // 302 prlimit64
// 	SYS_NAME_TO_HANDLE_AT, // 303 name_to_handle_at
// 	SYS_OPEN_BY_HANDLE_AT, // 304 open_by_handle_at
// 	SYS_CLOCK_ADJTIME, // 305 clock_adjtime
// 	SYS_SYNCFS, // 306 syncfs
// 	SYS_SENDMMSG, // 307 sendmmsg
// 	SYS_SETNS, // 308 setns
// 	SYS_GETCPU, // 309 getcpu
// 	SYS_PROCESS_VM_READV, // 310 process_vm_readv
// 	SYS_PROCESS_VM_WRITEV, // 311 process_vm_writev
// 	SYS_KCMP, // 312 kcmp
// 	SYS_FINIT_MODULE, // 313 finit_module
// 	SYS_SCHED_SETATTR, // 314 sched_setattr
// 	SYS_SCHED_GETATTR, // 315 sched_getattr
// 	SYS_RENAMEAT2, // 316 renameat2
// 	SYS_SECCOMP, // 317 seccomp
// 	SYS_GETRANDOM, // 318 getrandom
// 	SYS_MEMFD_CREATE, // 319 memfd_create
// 	SYS_KEXEC_FILE_LOAD, // 320 kexec_file_load
// 	SYS_BPF, // 321 bpf
// 	SYS_EXECVEAT, // 322 execveat
// 	SYS_USERFAULTFD, // 323 userfaultfd
// 	SYS_MEMBARRIER, // 324 membarrier
// 	SYS_MLOCK2, // 325 mlock2
// 	// Browsix-specific syscalls
// 	SYS_SPAWN, // 326 spawn
// }